package com.skivingcloud.admin.sys.controller;


import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.skivingcloud.admin.annotation.UserOperateLog;
import com.skivingcloud.admin.sys.entity.SysBusinessType;
import com.skivingcloud.admin.sys.service.ISysBusinessTypeService;
import com.skivingcloud.common.utils.PageUtils;
import com.skivingcloud.common.utils.R;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 业务类型定义 前端控制器
 * </p>
 *
 * @author skivingcloud
 * @since 2022-07-04
 */
@RestController
@RequestMapping("/sys/businessType")
public class SysBusinessTypeController {

	private static Logger log = LoggerFactory.getLogger(SysBusinessTypeController.class);
	
	@Autowired
	private ISysBusinessTypeService sysBusinessTypeService;

	/**
	 * 分页
	 */
	@PostMapping("/list")
	public R list(@RequestBody Map<String, Object> params) {
		/*Map<String, Object> params = new HashMap<String, Object>();
		params.put("page", page);
		params.put("limit", limit);
		params.put("dataForm", dataForm);*/
		PageUtils pages = sysBusinessTypeService.queryPage(params);
		return R.ok().put("page", pages);
	}

	/**
	 * 新增
	 * 
	 * @param sysBusinessType
	 * @return
	 */
	@UserOperateLog(module = "业务类型定义", methods = "save", description = "新增业务类型定义")
	@PostMapping("/save")
	public R save(@RequestBody SysBusinessType sysBusinessType) {
		try {
			sysBusinessTypeService.add(sysBusinessType);
			return R.ok();
		} catch (Exception e) {
			log.error("保存业务类型定义失败!", e);
			return R.error("保存业务类型定义失败!");
		}
	}

	/**
	 * 修改
	 * 
	 * @param sysBusinessType
	 * @return
	 */
	@UserOperateLog(module = "业务类型定义", methods = "update", description = "修改业务类型定义")
	@PostMapping("/update")
	public R update(@RequestBody SysBusinessType sysBusinessType) {
		try {
			sysBusinessTypeService.update(sysBusinessType);
			return R.ok();
		} catch (Exception e) {
			log.error("保存业务类型定义失败!", e);
			return R.error("保存业务类型定义失败!");
		}
	}

	/**
	 * 删除
	 * 
	 * @param ids
	 * @return
	 */
	@UserOperateLog(module = "业务类型定义", methods = "delete", description = "删除业务类型定义")
	@PostMapping("/delete")
	public R delete(@RequestBody String[] ids) {
		try {
			sysBusinessTypeService.deleteBatch(ids);
			return R.ok();
		} catch (Exception e) {
			log.error("删除业务类型定义失败!", e);
			return R.error("删除业务类型定义失败!");
		}
	}

	/**
	 * 根据主键查询
	 * 
	 * @param id
	 * @return
	 * @throws Exception
	 */
	@GetMapping("/info/{id}")
	public R info(@PathVariable("id") String id) throws Exception {
		SysBusinessType sysBusinessType = sysBusinessTypeService.selectById(id);
		return R.ok().put("data", sysBusinessType);
	}

	/*
	 * 查询业务类型分类
	 */
	@GetMapping("/getBusinessTypeList")
	public R getBusinessTypeList() throws Exception {
		List<SysBusinessType> list = sysBusinessTypeService.getBusinessTypeList();
		return R.ok().put("list", list);
	}

}
